/***********************************************************************
 * Module:  ClientRepository.java
 * Author:  SAGE-GENERATOR
 * Purpose: DDD: domain 领域层,仓储(Repository): 提供查找和持久化对象的方法
 ***********************************************************************/

package com.oweight.sagacious.auth.server.domain.repo;

import com.oweight.sagacious.auth.server.domain.entity.Client;
import com.oweight.sagacious.common.domain.repo.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 客户端：仓储
 *
 * @author SAGE
 * @version v1 2019-10-21 09:47:00
 */

public interface ClientRepository extends BaseRepository<Client, String> {

    /**
     * 获取指定服务端注册的客户端
     *
     * @param clientId
     * @return
     */
    @Query(value = "SELECT client.fd_code FROM sage_auth_client client " +
            "INNER JOIN sage_auth_client_service sacs " +
            "ON sacs.fd_client_id = client.fd_id " +
            "WHERE sacs.fd_service_id = " +
            "(SELECT sacs0.fd_service_id " +
            "FROM sage_auth_client_service sacs0 " +
            "WHERE sacs0.fd_client_id = :clientId)", nativeQuery = true)
    List<String> selectAllowedClient(@Param("clientId") String clientId);

    /**
     * 通过fdCode获取客户端
     *
     * @param code
     * @return
     */
    Client findByFdCode(String code);
}
//